<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Plasa extends CI_Controller {

    function __construct() {
        parent::__construct();

        $this->title = "SMILE | Selamat datang, telkom siap melayani Anda!";

        $this->load->helper(array('date', 'url'));
        $this->layout = "admin";

        $this->scripts = array("jquery", "jquery-ui", "jquery.dataTables.min");
        $this->styles = array("jquery-ui", "demo_table", "useradmin");
    }

    public function index() {
        if ($this->session->userdata('is_super_admin')) {
            
        } else if ($this->session->userdata('is_admin')) {
            redirect('admin/site/');
        } else if ($this->session->userdata('is_pic')) {
            redirect('admin/statistic');
        } else {
            redirect('admin/site/login');
        }

        $menudata['is_admin'] = $this->session->userdata('is_admin');
        $menudata['is_pic'] = $this->session->userdata('is_pic');
        $menudata['is_super_admin'] = $this->session->userdata('is_super_admin');
        $this->menubar = $this->load->view('admin/menubar', $menudata);

        $data["plasas"] = $this->plasamodel->get_all_plasa()->result_array();
        $this->load->view("admin/plasa_management", $data);
    }

    public function add() {
        $this->layout = false;

        $name = $this->input->post('name');
        $address = $this->input->post('address');
        $pic_contact = $this->input->post('pic_contact');

        echo $this->plasamodel->add_plasa($name, $address, $pic_contact);
    }
    
    public function getplasa($plasa_id) {
        $this->layout = false;
        //echo "nilai".$plasa_id;
        echo json_encode($this->plasamodel->get_plasa_info($plasa_id)->row_array());
    }
    
    public function update(){
        $this->layout = false;
        
        $plasa_id = $this->input->post('plasa_id');
        $name = $this->input->post('name');
        $address = $this->input->post('address');
        $pic_contact = $this->input->post('pic_contact');

        echo $this->plasamodel->update_plasa($plasa_id, $name, $address, $pic_contact);
    }
    
    public function delete() {
        $this->layout = false;

        echo $this->plasamodel->delete_plasa($this->input->post('plasa_id'));
    }
}

?>
